'''
Created on 2024年7月23日

@author: Administrator
'''

from pathlib import Path


def count_words(path):
    try:
        contents = path.read_text(encoding='utf-8')
    except FileNotFoundError:
        pass
#         print(f"Sorry,the file {path} does not exist.")
    else:
        words = contents.split()
        num_words = len(words)
        print(f"The file {path} has about {num_words} words.")
    

path = Path('alice.txt')
count_words(path)

filenames = ['a.txt','b.txt','alice.txt']
for filename in filenames:
    path = Path(filename)
    count_words(path)


